TypsScript インデックスシグネチャ
「どんな名前のプロパティも受け入れる」という性質のオブジェクト型を記述できる
code:ts
type HogeFuga = {
hoge: number;
fuga: string;
};
だとオブジェクトのプロパティ名は固定(hoge, fuga)
code:ts
type PriceData = {
};
const data: PriceData = {
apple: 200,
coffe: 300,
bento: 500,
};
// OK
data.chiken = 250;
// NG: Type "foo" is not assignable to type 'number'.
data.弁当 = "foo";